import functools

from flask import current_app
from flask import g
from flask import session




def do_index_class(index):
    if index == 0:
        return "first"
    elif index == 1:
        return "second"
    elif index == 2:
        return "third"
    else:
        return ""



# 用户登录装饰器
def user_login_data(f):
    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        # 获取当前登陆用户的id
        user_id = session.get("user_id")
        # 通过用户id获取用户信息
        user = None
        if user_id:

            from info.models import User
            user = User.query.get(user_id)
        # g变量，进行应用上下文传参
        g.user = user
        return f(*args, **kwargs)
    return wrapper